package com.water.camera.mark;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.water.camera.bean.EditItem;
import com.water.camera.databinding.LayoutWatermark19Binding;
import com.water.camera.util.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

public class Mark19 extends BaseMark {

    LayoutWatermark19Binding binding;

    public Mark19(@NonNull Context context) {
        super(context);
    }

    public Mark19(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public Mark19(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(int type) {
        if (type == 0) {
            binding = LayoutWatermark19Binding.inflate(LayoutInflater.from(getContext()));
            addView(binding.getRoot());
        } else {
            binding = LayoutWatermark19Binding.inflate(LayoutInflater.from(getContext()), this, true);
        }
        update();
        if (type == 0) {
            hideView(binding.binding8, binding.binding12, binding.binding14, binding.binding16);
        }
    }

    @Override
    public void update() {
        setText(binding.binding1, "title19", binding.binding1);
        setText(binding.binding2, "time19", binding.binding2);
        setTime(binding.binding2, new SimpleDateFormat("yyyy-MM-dd HH:mm"));
        if (!setWeek(binding.binding3, 1)) {
            binding.binding3.setText("周一");
        }
        setText(binding.binding5, "didan19", binding.binding4);
        setText(binding.binding7, "name19", binding.binding6);
        setText(binding.binding9, "sheshi19", binding.binding8);
        setText(binding.binding11, "qingkuang19", binding.binding10);
        setText(binding.binding13, "danwei19", binding.binding12);
        setText(binding.binding15, "ren19", binding.binding14);
        setText(binding.binding17, "beizhu19", binding.binding16);

        super.update();
    }

    @Override
    public ArrayList<EditItem> getEditItems() {
        ArrayList<EditItem> list = new ArrayList<>();
        list.add(new EditItem("title19", "标题"));
        list.add(new EditItem("time19", "时间", true));
        list.add(new EditItem("didian19", "地址"));
        list.add(new EditItem("name19", "道路名称"));
        list.add(new EditItem("sheshi19", "道路设施"));
        list.add(new EditItem("qingkuang19", "道路情况"));
        list.add(new EditItem("danwei19", "单位"));
        list.add(new EditItem("ren19", "巡检人"));
        list.add(new EditItem("beizhu19", "备注"));
        return list;
    }

    @Override
    public void onValueChange(EditItem item) {
        if (item.isTime) {
            setTime(binding.binding2, new SimpleDateFormat("yyyy-MM-dd HH:mm"));
            setWeek(binding.binding3, 1);
        } else {
            super.onValueChange(item);
        }
    }

    @Override
    public void onShowChange(EditItem item) {
        if (item.isTime) {
            if (!item.show) {
                binding.binding2.setVisibility(View.GONE);
                binding.binding3.setVisibility(View.GONE);
            } else {
                binding.binding2.setVisibility(View.VISIBLE);
                binding.binding3.setVisibility(View.VISIBLE);
            }
        } else {
            super.onShowChange(item);
        }
    }
}
